package com.core.family.admin.Interceptor;

import lombok.SneakyThrows;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @program: kuntail
 * @description:
 * @author: honglei
 * @create: 2022-04-08 16:15
 */
@Aspect
@Component
public class MenuDescAspec {

    /*切点扫描某个包下某个加了注解的方法,如果只加注解类就会全部扫描*/
    @Pointcut("execution(* com.core.family..controller.*.*(..))")
    public void targetMyAspec() {

    }

    //环绕通知
    @SneakyThrows
    @Around("targetMyAspec()")
    public Object Interceptor(ProceedingJoinPoint pjp) {
        Object result = null;


        Class<?> aClass = pjp.getTarget().getClass();//获得所在切点的该类的class对象，也就是UserController这个类的对象


        String name = pjp.getSignature().getName();//获取该切点所在方法的名称，也就是listUser
//        try {
////            Method method = aClass.getMethod(name);//通过反射获得该方法
////            MyLog annotation = method.getAnnotation(MyLog.class);//获得该注解
////            System.out.println(annotation.value());//获得自定义注解上面的值
//        } catch (NoSuchMethodException e) {
//            e.printStackTrace();
//        }

        result = pjp.proceed();//执行该方法
//        try {
//            result = pjp.proceed();//执行该方法
//        } catch (Throwable e) {
//            e.printStackTrace();
//        }
        return result;
    }
}
